/***************************************************************
 *
 * (c) 2008 Markus Dittrich 
 *
 * This program is free software; you can redistribute it 
 * and/or modify it under the terms of the GNU General Public 
 * License Version 3 as published by the Free Software Foundation. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License Version 3 for more details.
 *
 * You should have received a copy of the GNU General Public 
 * License along with this program; if not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA 02111-1307, USA.
 *
 ****************************************************************/

#ifndef DATACOMPUTEENGINE_H 
#define DATACOMPUTEENGINE_H 

/* boost includes */
#include <boost/utility.hpp>

/* STL includes */
#include <functional>
#include <vector>

/* stdlib include */
#include <cmath>

/* local includes */
#include "data_object.h"

/* forward declarations */
class QString;


/****************************************************************
 *
 * class ComputeEngine provides the abstrace interface for 
 * classes that transform a vector<double> of data and return
 * a new DataObject;
 *
 ***************************************************************/
class ComputeEngine 
{

public:

  explicit ComputeEngine() {};
  virtual ~ComputeEngine() {};

  virtual DataObjectPtr compute(const std::vector<double>& data) = 0;
};



/****************************************************************
 *
 * class HistogramEngine computes the histogram of a given
 * data set
 *
 ***************************************************************/
class HistogramComputeEngine 
  : 
    public ComputeEngine,
    public boost::noncopyable
{

public:

  explicit HistogramComputeEngine(int numBins, bool normalize);
  virtual ~HistogramComputeEngine() {};

  DataObjectPtr compute(const std::vector<double>& data);


private:

  /* member functions */
  DataObjectPtr compute_(const std::vector<double>& data);
  DataObjectPtr generate_data_object_(const std::vector<double>&
      binLocations, const std::vector<double>& binValues);

  /* data members */
  int NumBins_;
  bool normalize_;
};




/*****************************************************************
 *
 * function object used to normalize a histogram 
 *
 ******************************************************************/
template<class T1, class T2> struct divide_by : 
  public std::binary_function<T1, T2, void> 
{
  void operator() (T1& x, T2 divisor) const {
    x /= divisor;
  }
};

#endif
